package com.ship.dispatch.bean.orderPay;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ship.common.core.base.BaseBean;
import com.ship.common.core.base.Joinable;
import com.ship.common.core.enums.CurrencyStatus;
import com.ship.common.core.enums.OrderStatus;
import com.ship.common.core.enums.OrderType;
import com.ship.common.core.mapping.Label;
import com.ship.common.core.mapping.SearchItem;
import com.ship.common.core.mapping.TableColumn;
import com.ship.dispatch.util.NumberFormatUtil;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 支付结算表
 */
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("sp_payment_order")
public class SpPaymentOrder extends BaseBean implements Joinable {
    /**
     * 订单编号
     */
    @Label(value = "订单编号")
    @SearchItem
    @TableColumn
    @TableField("pay_order_number")
    private String payOrderNumber;

    /**
     * 订单类型
     */
    @Label(value = "订单类型")
    @SearchItem
    @TableColumn
    @TableField("order_type")
    private Integer orderType;

    @TableField(exist = false)
    private String orderTypeListForSearch;

    /**
     * 船舶名称
     */
    @TableField("ship_name")
    private String shipName;
    /**
     * 预计装载时间
     */
    @TableField("expected_loading_date")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date expectedLoadingDate;
    /**
     * 预计卸载时间
     */
    @TableField("expected_unloading_date")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date expectedUnloadingDate;
    /**
     * 预计装载港
     */
    @TableField("expected_loading_port")
    private String expectedLoadingPort;
    /**
     * 预计卸载港
     */
    @TableField("expected_unloading_port")
    private String expectedUnloadingPort;

    /**
     * 订单类型字符串
     */
    @Label(value = "订单类型")
    @TableField(exist = false)
    @TableColumn
    private String orderTypeStr;

    /**
     * 用户输入订单类型
     */
    @TableField("order_type_text")
    private String orderTypeText;

    /**
     * 币种字符串
     */
    @Label(value = "币种")
    @TableField(exist = false)
    @TableColumn
    private String payAmountUnitStr;

    /**
     * 支付金额
     */
    @Label(value = "支付金额")
    @SearchItem
    @TableColumn
    @TableField(exist = false)
    private String payAmountStr;

    /**
     * 航次号
     */
    @Label(value = "航次号")
    @SearchItem
    @TableColumn
    @TableField("voyage_no")
    private String voyageNo;

    /**
     * 关联合同id
     */
    @TableField("contract_id")
    private Long contractId;

    /**
     * 关联合同名称
     */
    @Label(value = "关联合同")
    @SearchItem
    @TableColumn
    @TableField("contract_name")
    private String contractName;

    /**
     * 合同类型（1：船舶代理合同、2：保险合同（货险、人险）、3：第三方计量合同、4：租金相关合同--船运合同、5：加油合同）
     */
    @TableField("contract_type")
    private Integer contractType;

    /**
     * 关联合同地址
     */
    @TableField("contract_address")
    private String contractAddress;

    /**
     * 支付金额
     */
    @Label(value = "支付金额")
    @SearchItem
    @TableField("pay_amount")
    private BigDecimal payAmount;

    /**
     * 支付金额单位（1：美元、2：欧元、3：人民币）
     */
    @TableField("pay_amount_unit")
    private Integer payAmountUnit;

    /**
     * 截止支付时间
     */
    @Label(value = "截止支付时间")
    @TableField("pay_end_time")
    private Date payEndTime;

    @Label(value = "截止支付时间")
    @TableField(exist = false)
    private String payEndTimeStr;

    /**
     * 申请人
     */
    @Label(value = "申请人")
    @SearchItem
    @TableColumn
    @TableField("applicant_people")
    private String applicantPeople;

    /**
     * 经办人
     */
    @Label(value = "经办人")
    @SearchItem
    @TableColumn
    @TableField("handle_people")
    private String handlePeople;

    /**
     * 审批人
     */
    @Label(value = "审批人")
    @SearchItem
    @TableColumn
    @TableField("approved_people")
    private String approvedPeople;

    /**
     * 订单状态（1：未审核、2：已审核、3：已付款）
     */
    @Label(value = "订单状态（1：未审核、2：已审核、3：已付款）")
    @SearchItem
//    @TableColumn
    @TableField("order_status")
    private Integer orderStatus;

    @TableField(exist = false)
    private String orderStatusListForSearch;

    /**
     * 订单状态字符串
     */
    @Label(value = "订单状态（1：未审核、2：已审核、3：已付款）")
    @SearchItem
    @TableColumn
    @TableField(exist = false)
    private String orderStatusStr;

    /**
     * 备注
     */
    @Label(value = "备注")
    @SearchItem
    @TableColumn
    @TableField("order_remark")
    private String orderRemark;

    /**
     * 创建时间
     */
    @TableField("create_date")
    private Date createDate;

    /**
     * 创建人
     */
    @TableField("create_by")
    private String createBy;

    /**
     * 是否同步（1：同步，2：未同步）
     */
    @TableField("order_synchronous")
    private Integer orderSynchronous;

    private Integer approverStatus;

    private String processInstanceId;

    @Override
    public String getLabel() {
        return null;
    }

    @Override
    public String getValue() {
        return null;
    }

    public String getPayAmountStr() {
        String result = null;
        if (getPayAmount() != null) {
            result = NumberFormatUtil.numericFormatting(payAmount) + getPayAmountUnitStr();
        }
        return result;
    }

    public String getPayAmountUnitStr() {
        String result = null;
        if (getPayAmountUnit() != null) {
            if (payAmountUnit.equals(CurrencyStatus.DOLLAR.getCode())) {
                result = CurrencyStatus.DOLLAR.getInfo();
            } else if (payAmountUnit.equals(CurrencyStatus.EURO.getCode())) {
                result = CurrencyStatus.EURO.getInfo();
            } else if (payAmountUnit.equals(CurrencyStatus.RMB.getCode())) {
                result = CurrencyStatus.RMB.getInfo();
            }
        }
        return result;
    }

    public String getPayEndTimeStr() {
        Date now = getPayEndTime();
        if (now != null) {
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy年MM月dd日");
            return formatter.format(now);
        } else {
            return ""; // 或者返回其他默认值，视情况而定
        }
    }

    public String getOrderStatusStr() {
        String result = null;
        if (getOrderStatus() != null) {
            if (orderStatus.equals(OrderStatus.UNAUDITE.getCode())) {
                result = OrderStatus.UNAUDITE.getInfo();
            } else if (orderStatus.equals(OrderStatus.AUDITE.getCode())) {
                result = OrderStatus.AUDITE.getInfo();
            } else if (orderStatus.equals(OrderStatus.PAID.getCode())) {
                result = OrderStatus.PAID.getInfo();
            }
        }
        return result;
    }

    public String getOrderTypeStr() {
        String result = null;
        if (getOrderType() != null) {
            if (orderType.equals(OrderType.LOADING_PORT_PAY.getCode())) {
                result = OrderType.LOADING_PORT_PAY.getInfo();
            } else if (orderType.equals(OrderType.LOADING_PORT_PAY_END.getCode())) {
                result = OrderType.LOADING_PORT_PAY_END.getInfo();
            } else if (orderType.equals(OrderType.UNLOADING_PORT_PAY.getCode())) {
                result = OrderType.UNLOADING_PORT_PAY.getInfo();
            } else if (orderType.equals(OrderType.UNLOADING_PORT_PAY_END.getCode())) {
                result = OrderType.UNLOADING_PORT_PAY_END.getInfo();
            } else if (orderType.equals(OrderType.CHARTERER_INSURANCE.getCode())) {
                result = OrderType.CHARTERER_INSURANCE.getInfo();
            } else if (orderType.equals(OrderType.CARGO_INSURANCE.getCode())) {
                result = OrderType.CARGO_INSURANCE.getInfo();
            } else if (orderType.equals(OrderType.LOADING_PORT_THIRD_PARTY.getCode())) {
                result = OrderType.LOADING_PORT_THIRD_PARTY.getInfo();
            } else if (orderType.equals(OrderType.UNLOADING_PORT_THIRD_PARTY.getCode())) {
                result = OrderType.UNLOADING_PORT_THIRD_PARTY.getInfo();
            } else if (orderType.equals(OrderType.SHIP_RENTAL.getCode())) {
                result = OrderType.SHIP_RENTAL.getInfo();
            } else if (orderType.equals(OrderType.SHIP_NEXT_RENTAL.getCode())) {
                result = OrderType.SHIP_NEXT_RENTAL.getInfo();
            } else if (orderType.equals(OrderType.SHIP_END_RENTAL.getCode())) {
                result = OrderType.SHIP_END_RENTAL.getInfo();
            } else if (orderType.equals(OrderType.DELIVERY_FEE.getCode())) {
                result = OrderType.DELIVERY_FEE.getInfo();
            } else if (orderType.equals(OrderType.RETURN_SHIP_FEE.getCode())) {
                result = OrderType.RETURN_SHIP_FEE.getInfo();
            } else if (orderType.equals(OrderType.LNG_DELIVERY_FEE.getCode())) {
                result = OrderType.LNG_DELIVERY_FEE.getInfo();
            } else if (orderType.equals(OrderType.LNG_RETURN_FEE.getCode())) {
                result = OrderType.LNG_RETURN_FEE.getInfo();
            } else if (orderType.equals(OrderType.FUEL_DELIVERY_SETTLE.getCode())) {
                result = OrderType.FUEL_DELIVERY_SETTLE.getInfo();
            } else if (orderType.equals(OrderType.FUEL_RETURN_SETTLE.getCode())) {
                result = OrderType.FUEL_RETURN_SETTLE.getInfo();
            } else if (orderType.equals(OrderType.FUEL_INJECTION.getCode())) {
                result = OrderType.FUEL_INJECTION.getInfo();
            } else {
                result = orderTypeText;
            }
        } else {
            result = orderTypeText;
        }
        return result;
    }
}
